home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / ScottsSoul.sit / Scott's Soul / Beep.c next >
C/C++ Source or Header  |  1996-06-21  |  3KB  |  138 lines

  1. // Note: This will not work with Copland.  Don't even think of it.
  2.  
  3. #include <Events.h>
  4. #include <Resources.h>
  5. #include <Memory.h>
  6. #include <ToolUtils.h>
  7. #include <Traps.h>
  8. #include <Balloons.h>
  9. #include <Sound.h>
  10.  
  11. #include <A4Stuff.h>
  12.  
  13. #define kOptionKey    0x3A
  14.  
  15. PicHandle        gDogCow;
  16. PicHandle        gScottSuckup;
  17.  
  18. Boolean isPressed(unsigned short k );
  19. extern pascal void ShowIcon7(short iconId, Boolean advance);
  20. pascal void (*gOldSysBeep)(short notUsedAnyMore);
  21. pascal void HelpSysBeep(short notUsedAnyMore);
  22.  
  23. // This procedure is called one time at system startup.  I install my
  24. // patch to the SysBeep call.  After this, whenever the system calls
  25. // SysBeep, my code in "HelpSysBeep" will be executed instead.
  26. void main(void)
  27. {
  28.     long    oldA4;
  29.     THz        oldZone;
  30.  
  31.         // Set up A4, so we can access our globals.
  32.     oldA4 = SetCurrentA4();
  33.     
  34.     ShowIcon7(128, true);
  35.         // Set the current zone to the system zone.  In the 680x0 case, this
  36.         // is not necessary, but it's not a bad idea and it keeps us out of
  37.         // trouble when traps that we don't expect to have side effects
  38.         // unexpectedlty allocate memory from the current zone.  One example
  39.         // of this is the NewRoutineDescriptor routine.
  40.     oldZone = GetZone();
  41.     SetZone(SystemZone());
  42.         // We need to detach our code, so that we stay around.
  43.     DetachResource(GetResource('INIT', -4048));
  44.  
  45.         // Get our dogcow beep picture
  46.     gDogCow = (PicHandle)GetResource('PICT', 1000);
  47.     DetachResource((Handle)gDogCow);
  48.     
  49.         // Get our ScottSuckup beep picture
  50.     gScottSuckup = (PicHandle)GetResource('PICT', 1);
  51.     DetachResource((Handle)gScottSuckup);
  52.     
  53.  
  54. #ifdef DOESNOTWORK
  55.         // Get our dogcow beep sound
  56.     gDogCowSound = (SndListHandle)GetResource('snd ', 1000);
  57.     DetachResource((Handle)gDogCowSound);
  58. #endif
  59.     
  60.  
  61.         // Remember the old implementation of SysBeep.
  62.     gOldSysBeep = (void *) GetToolTrapAddress(_SysBeep);
  63.  
  64.         // Patch ourselves in.
  65.     SetToolTrapAddress( (ProcPtr) HelpSysBeep, _SysBeep);
  66.  
  67.         // Restore the old zone again
  68.     SetZone(oldZone);
  69.  
  70.         // And restore the value of A4 on the way out.
  71.     SetA4(oldA4);
  72. }
  73.  
  74. // This is my replacement to SysBeep.  After we have set the SysBeep
  75. // trap to point here (up in "main") then whenever anyone calls the
  76. // SysBeep trap, we execute here instead.
  77. pascal void HelpSysBeep(short notUsedAnyMore)
  78. {
  79. #pragma unused (notUsedAnyMore)
  80.  
  81.     long            oldA4;
  82.     Boolean            helpIsOn;
  83.     HMMessageRecord    aHelpMsg;
  84.     Point            tip;
  85.  
  86.         // Set up A4, so we can access our globals.
  87.     oldA4 = SetCurrentA4();
  88.  
  89.     helpIsOn = HMGetBalloons();
  90.     
  91.         // turn on help if it isn't on
  92.     if (helpIsOn == false)
  93.         HMSetBalloons(true);
  94.     
  95.         // display a 'PICT' instead of beeping
  96.     aHelpMsg.hmmHelpType = khmmPictHandle;
  97.     if (isPressed(kOptionKey))
  98.         aHelpMsg.u.hmmPictHandle = gDogCow;
  99.     else
  100.         aHelpMsg.u.hmmPictHandle = gScottSuckup;
  101.  
  102.         // if you wanted a pure text string instead, use this:
  103.     //aHelpMsg.hmmHelpType = khmmString;
  104.     //BlockMove ("\pBeep!", aHelpMsg.u.hmmString, 6);
  105.     
  106.     GetMouse(&tip);
  107.     LocalToGlobal(&tip);
  108.     
  109.         // Show the balloon
  110.     HMShowBalloon(&aHelpMsg,tip,nil,nil,0,0,kHMSaveBitsNoWindow);
  111.  
  112.         // Call the old SysBeep:
  113.     gOldSysBeep(notUsedAnyMore);
  114.     
  115.     while (Button())
  116.         ;
  117.  
  118.         // turn off help if it wasn't on coming into this patch
  119.     if (helpIsOn == false)
  120.         HMSetBalloons(false);
  121.         
  122.         // And restore the value of A4 on the way out.
  123.     SetA4(oldA4);
  124.  
  125.     return;
  126. }
  127.  
  128.  
  129. Boolean isPressed(unsigned short k )
  130. // k =  any keyboard scan code, 0-127
  131. {
  132.     unsigned char km[16];
  133.  
  134.     GetKeys( (unsigned long *) km);
  135.     return ( ( km[k>>3] >> (k & 7) ) & 1);
  136. }
  137.  
  138.